﻿@using SDF.Core
@using SDF.Services.Common
@model SimpleDevelopFrameworkNewsModel

@{
    const string panelId = "SimpleDevelopFramework-news-box";
    const string hidePanelAttributeName = "HideSimpleDevelopFrameworkNewsPanel";
    var hidePanel = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.GetAttribute<bool>(hidePanelAttributeName);
}

<div class="box box-info @if(hidePanel){<text>collapsed-box</text>}" id="@panelId">
    <div class="box-header with-border clearfix">
        <div class="box-title">
            <i class="fa fa-newspaper-o"></i>
            @T("Admin.SimpleDevelopFrameworkNews")
            @if (Model.HasNewItems)
            {
                <div class="new-item-notification"><span>+1</span></div>
            }
        </div>
        <div class="box-tools pull-right">
            <button type="button" class="btn btn-box-tool" data-widget="collapse">
                @if (hidePanel)
                {
                    <text><i class="fa fa-plus"></i></text>
                }
                else
                {
                    <text><i class="fa fa-minus"></i></text>
                }
            </button>
        </div>
    </div>
    <div class="box-body">
        <div class="row">
            @foreach (var item in Model.Items)
            {
                <div class="col-md-4">
                    <div class="panel panel-info">
                        <div class="panel-heading clearfix">
                            @if (!String.IsNullOrEmpty(item.Url))
                            {
                                <a class="pull-left" href='@(item.Url)'>@item.Title</a>
                            }
                            else
                            {
                                <div class="pull-left">@item.Title</div>
                            }
                            @*<div class="pull-right">@item.PublishDate.ToString("d")</div>*@
                        </div>
                        <div class="panel-body">
                            @Html.Raw(item.Summary)
                        </div>
                    </div>
                </div>
            }
        </div>

        <script>
            $(document).ready(function () {
                $('#@panelId').on('click', 'button[data-widget="collapse"]', function () {
                    var collapsed = !$('#@panelId').hasClass('collapsed-box');
                    saveUserPreferences('@(Url.Action("SavePreference", "Preferences"))', '@hidePanelAttributeName', collapsed);
                });
            });
        </script>
    </div>
    @*<div class="box-footer">
            <button id="SimpleDevelopFrameworkNewsHideAdv" class="btn bg-aqua">
                @(Model.HideAdvertisements ? T("Admin.SimpleDevelopFrameworkNews.ShowAdv") : T("Admin.SimpleDevelopFrameworkNews.HideAdv"))
            </button>
            <script type="text/javascript">
                $(document).ready(function () {
                    $('#SimpleDevelopFrameworkNewsHideAdv').click(function () {
                        var postData = {
                        };
                        addAntiForgeryToken(postData);

                        $.ajax({
                            cache: false,
                            type: "POST",
                            url: "@(Url.Action("SimpleDevelopFrameworkNewsHideAdv", "Home"))",
                            data: postData,
                            success: function (data) {
                                location.reload();
                            },
                            error: function (xhr, ajaxOptions, thrownError) {
                                alert('Failed to change setting.');
                            }
                        });
                    });
                });
            </script>
        </div>*@
</div>
